﻿using OZDoo.Core.Providers;
using OZDoo.Core.Caching;

namespace OZDoo.Core.Log
{
    /// <summary>
    /// 日志记录管理类
    /// </summary>
    public class LogManage
    {
        /// <summary>
        /// 日志记录提供者默认名称
        /// </summary>
        private static string providername = "Logger";
       
        /// <summary>
        /// 获得一个日志记录实例
        /// </summary>
        /// <returns>日志记录接口对象</returns>
        public static ILog GetLogger()
        {
            ILog _log = CacheService.Get(CacheKey) as ILog;
            if (_log == null)
            {
                LogProvider _logprovider = ProviderManage.getProvider<LogProvider>(OzdConfiguration.ProviderSectionName, providername);
                if (_logprovider == null) _log = new FakeLog();
                else _log = (ILog)_logprovider;
                CacheService.Max(CacheKey, _log);
            }
            return _log;
        }

        private static string CacheKey {
             get
             {
                 return providername;
             }
        }
    }
}
